package com.zimin.cloud.wiki.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zimin.cloud.mine.pojo.wiki.business.EbookBO;
import com.zimin.cloud.mine.pojo.wiki.view.EbookVO;
import com.zimin.cloud.wiki.biz.IEbookBiz;
import com.zimin.cloud.wiki.controller.api.IEbookController;
import com.zimin.shared.pojo.BaseController;
import com.zimin.shared.pojo.PageVO;
import com.zimin.shared.pojo.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 电子书 前端控制器
 * </p>
 *
 * @author zimin
 * @since 2021-10-27 21:02
 */
@RestController
public class EbookController extends BaseController implements IEbookController {

    private final IEbookBiz ebookBiz;

    /**
     * <p>构造器注入，这种方式注入spring的bean会让两层之间的耦合尽可能的低</p>
     *
     * @param ebookBiz
     * @return
     * @author zimin
     * @since 2021-10-29 15:01:04
     */
    public EbookController(IEbookBiz ebookBiz) {
        this.ebookBiz = ebookBiz;
    }

    @Override
    public Result ebookList(Page page, EbookBO ebookBO) {
        PageVO<EbookVO> ebookVOList= ebookBiz.list(page, ebookBO);
        return Result.ok(ebookVOList);
    }

    @Override
    public Result saveEbook(EbookBO ebookBO) {

        return result(ebookBiz.save(ebookBO));
    }

    @Override
    public Result updateEbook(@Validated EbookBO ebookBO) {
        return result(ebookBiz.updateById(ebookBO));
    }

    @Override
    public Result removeById(String id) {
        return result(ebookBiz.removeById(id));
    }

}
